package com.examples.oryarok;

import static com.examples.oryarok.Constants.TABLE_NAME;
import android.app.TabActivity;
import android.content.Intent;
import android.content.res.Resources;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.TabHost;
import com.examples.oryarok.MeetDataDbHelper;;


public class HelloTabWidget extends TabActivity {
	private MeetDataDbHelper meetEntry;
	public static String dayTemp;
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	    setContentView(R.layout.main_tab);
	    
	    
	    dayTemp = "";	    
	    Resources res = getResources(); // Resource object to get Drawables
	    TabHost tabHost = getTabHost();  // The activity TabHost
	    TabHost.TabSpec spec;  // Resusable TabSpec for each tab
	    Intent intent;  // Reusable Intent for each tab

	    // Create an Intent to launch an Activity for the tab (to be reused)
	    
	    /*
	     * Dayly Tab 
	     */
	    intent = new Intent().setClass(this, DaylyList.class);
	    spec = tabHost.newTabSpec("dayly").setIndicator("Day",
	                      res.getDrawable(R.drawable.ic_tab_dayly))
	                  .setContent(intent);
	    tabHost.addTab(spec);
	    
	    /*
	     * Weekly Tab 
	     */
	    intent = new Intent().setClass(this, WeeklyList.class);
	    spec = tabHost.newTabSpec("weekly").setIndicator("Week",
	                      res.getDrawable(R.drawable.ic_tab_weekly))
	                  .setContent(intent);
	    tabHost.addTab(spec);
	    
	    /*
	     * Monthly Tab 
	     */
	    intent = new Intent().setClass(this, MonthlyList.class);
	    spec = tabHost.newTabSpec("monthly").setIndicator("Month",
	                      res.getDrawable(R.drawable.ic_tab_monthly))
	                  .setContent(intent);
	    tabHost.addTab(spec);
	    
	    /*
	     * List Tab 
	     */
	    intent = new Intent().setClass(this, ListList.class);
	    spec = tabHost.newTabSpec("list").setIndicator("List",
	                      res.getDrawable(R.drawable.ic_tab_list))
	                  .setContent(intent);
	    tabHost.addTab(spec);

	    tabHost.setCurrentTab(0);
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		super.onCreateOptionsMenu(menu);
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.menu, menu);
		return true;
	}
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case R.id.settings:
			startActivity(new Intent(this, Prefs.class));
			return true;
		case R.id.refresh:
			//TODO refresh
//			meetEntry = new MeetData(this);
//			SQLiteDatabase db = meetEntry.getWritableDatabase();
		case R.id.add:
			startActivity(new Intent(this, AddEntry.class));
			return true;
		case R.id.clear_db:
			meetEntry = new MeetDataDbHelper(this);
			SQLiteDatabase db = meetEntry.getWritableDatabase();
			db.execSQL("DROP TABLE IF EXIST " + TABLE_NAME);
			meetEntry.onCreate(db);
			meetEntry.close();
			return true;	
			// More items go here (if any) ...
		}
		return false;
	}

}
